from django.db import models

# Create your models here.

# 超链接表
from django.utils import timezone


# 传送门
class DB_href(models.Model):
    name = models.CharField(max_length=30, null=True, blank=True)
    url = models.CharField(max_length=500, null=True, blank=True, default="")

    # 让类默认返回一个字符串
    def __str__(self):
        return str(self.name)


# 公告表
class DB_notice(models.Model):
    ctime = models.DateTimeField("保存时间", default=timezone.now)
    content = models.CharField(max_length=1000, null=True, blank=True)

    def __str__(self):
        return str(self.content)  # 加上 str 是为了防止数据为None时删除报错问题


# 官方工具步骤表
class DB_GM_steps(models.Model):
    tool_id = models.CharField("所属工具", max_length=100, default="")
    #
    filter_id = models.CharField("过滤id", max_length=100, default="", null=True, blank=True)
    method = models.CharField("类型   r-请求 s-sql l-linux", max_length=100, null=True, blank=True, default="r")
    name = models.CharField("名字", max_length=100, null=True, blank=True, default="")
    delay_before = models.IntegerField("执行前延迟x秒", default=0)
    delay_after = models.IntegerField("执行后延迟x秒", default=0)
    ifdo = models.BooleanField("是否执行", default=True)  # 一共10步，不想执行完全部，只想到第三步，后面的就全部关掉
    docounts = models.IntegerField("执行次数", default=1)
    retry = models.IntegerField("重试次数", default=0)
    timeout = models.IntegerField("最大等待时间 s", default=60)
    order = models.IntegerField("执行顺序")  # 不使用自增形式，不够灵活
    final_res_re = models.CharField("最终返回结果--正则", max_length=200,default="", null=True,blank=True)
    # sql
    sql_fixture = models.CharField("sql组件id", max_length=500, null=True, blank=True, default="")
    sql_body = models.CharField("sql语句体", max_length=500, null=True, blank=True, default="")
    sql_assert_str = models.CharField("sql断言返回值字符串-表达式", max_length=200, null=True, blank=True, default="")
    sql_extract_index = models.CharField("sql 下标提取作为临时变量", max_length=200, null=True, blank=True, default="")
    # linux
    linux_fixture = models.CharField("linux组件id", max_length=500, null=True, blank=True, default="")
    linux_body = models.CharField("linux语句体", max_length=500, null=True, blank=True, default="")
    linux_assert_str = models.CharField("linux断言返回值字符串-表达式", max_length=200, null=True, blank=True, default="")
    linux_extract_re = models.CharField("linux 正则 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    # requests
    request_method = models.CharField("请求方式", max_length=100, null=True, blank=True, default="get")
    request_url = models.CharField("请求url", max_length=1000, null=True, blank=True, default="http://")
    request_body = models.CharField("请求体", max_length=2000, null=True, blank=True, default="")
    request_body_method = models.CharField("请求体类型", max_length=100, null=True, blank=True, default="form-data")
    request_headers = models.CharField('请求头', max_length=1000, null=True, blank=True, default='{}')
    request_sign = models.BooleanField("是否加密验签", default=False)
    request_cert = models.BooleanField("是否带证书", default=False)
    request_assert_str = models.CharField("request 断言返回值字符串--表达式", max_length=200, null=True, blank=True, default="")
    request_assert_path = models.CharField("request 断言返回值字符串--路径法", max_length=200, null=True, blank=True, default="")
    request_extract_re = models.CharField("request 正则 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    request_extract_path = models.CharField("request 路径法 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    request_proxy = models.BooleanField("是否代理", default=False)
    request_group = models.IntegerField("分组--登录态持久化 0 为组长", default=0)  # cookie 持久化

    def __str__(self):
        return str(self.name)


# 环境变量
class DB_PAR(models.Model):
    name = models.CharField("名字", max_length=50, null=True, blank=True, default="")
    code = models.CharField("代码", max_length=2000, null=True, blank=True, default="")

    def __str__(self):
        return self.name


# 服务器组件
class DB_LINUX(models.Model):
    name = models.CharField("名字", max_length=200, null=True, blank=True, default="")
    host = models.CharField("服务器地址ip", max_length=50, null=True, blank=True, default="")
    port = models.IntegerField("端口号", default=0)
    username = models.CharField("用户名", max_length=50, null=True, blank=True, default="")
    password = models.CharField("密码", max_length=50, null=True, blank=True, default="")

    def __str__(self):
        return str(self.name)


# 数据库组件
class DB_SQL(models.Model):
    name = models.CharField("名字", max_length=200, null=True, blank=True, default="")
    host = models.CharField("数据库地址ip", max_length=50, null=True, blank=True, default="")
    port = models.IntegerField("端口号", default=0)
    db_name = models.CharField("数据库名字", max_length=200, null=True, blank=True, default="")
    username = models.CharField("用户名", max_length=50, null=True, blank=True, default="")
    password = models.CharField("密码", max_length=50, null=True, blank=True, default="")

    def __str__(self):
        return str(self.id)+ ":" + str(self.name)


class DB_GM_tools(models.Model):
    name = models.CharField(max_length=100, null=True, blank=True, default="")

    def __str__(self):
        return str(self.name)


# 自定义工具表
class DB_DIY_tools(models.Model):
    name = models.CharField("工具名字",max_length=100, null=True, blank=True, default="")
    des = models.CharField("工具描述", max_length=200, null=True, blank=True, default="请添加描述")
    owner = models.CharField("创建者", max_length=100, null=True, blank=True, default="1")
    # 把自定义工具中所有的输入都放在一个大字符串中存储，然后解析生成前端页面，对前端压力会比较大，但是优点是前端能保持了你创建这些输入的顺序
    all_inputs = models.TextField("所有输入设置", max_length=1000, null=True, blank=True,default="[]")
    # log = models.TextField('日志',default='')

    # 如果是分类型去存，则在前端渲染的时候会失去顺序，前端的压力会小，但是不符合用户使用习惯，所以还是使用前一种设计
    # input
    # radio
    # checkbox
    # select


    def __str__(self):
        return str(self.name)


# 自定义工具步骤表
class DB_DIY_steps(models.Model):
    log = models.TextField('日志',default='', null=True, blank=True)
    tool_id = models.CharField("所属工具", max_length=100, default="")
    filter_id = models.CharField("过滤id", max_length=100, default="", null=True, blank=True)
    method = models.CharField("类型   r-请求 s-sql l-linux", max_length=100, null=True, blank=True, default="r")
    name = models.CharField("名字", max_length=100, null=True, blank=True, default="")
    delay_before = models.IntegerField("执行前延迟x秒", default=0)
    delay_after = models.IntegerField("执行后延迟x秒", default=0)
    ifdo = models.BooleanField("是否执行", default=True)  # 一共10步，不想执行完全部，只想到第三步，后面的就全部关掉
    docounts = models.IntegerField("执行次数", default=1)
    retry = models.IntegerField("重试次数", default=0)
    timeout = models.IntegerField("最大等待时间 s", default=60)
    order = models.IntegerField("执行顺序")  # 不使用自增形式，不够灵活
    final_res_re = models.CharField("最终返回结果--正则", max_length=200,default="", null=True,blank=True)
    # sql
    sql_fixture = models.CharField("sql组件id", max_length=500, null=True, blank=True, default="")
    sql_body = models.CharField("sql语句体", max_length=500, null=True, blank=True, default="")
    sql_assert_str = models.CharField("sql断言返回值字符串-表达式", max_length=200, null=True, blank=True, default="")
    sql_extract_index = models.CharField("sql 下标提取作为临时变量", max_length=200, null=True, blank=True, default="")
    # linux
    linux_fixture = models.CharField("linux组件id", max_length=500, null=True, blank=True, default="")
    linux_body = models.CharField("linux语句体", max_length=500, null=True, blank=True, default="")
    linux_assert_str = models.CharField("linux断言返回值字符串-表达式", max_length=200, null=True, blank=True, default="")
    linux_extract_re = models.CharField("linux 正则 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    # requests
    request_method = models.CharField("请求方式", max_length=100, null=True, blank=True, default="get")
    request_url = models.CharField("请求url", max_length=1000, null=True, blank=True, default="http://")
    request_body = models.CharField("请求体", max_length=2000, null=True, blank=True, default="")
    request_body_method = models.CharField("请求体类型", max_length=100, null=True, blank=True, default="form-data")
    request_headers = models.CharField('请求头', max_length=1000, null=True, blank=True, default='{}')
    request_sign = models.BooleanField("是否加密验签", default=False)
    request_cert = models.BooleanField("是否带证书", default=False)
    request_assert_str = models.CharField("request 断言返回值字符串--表达式", max_length=200, null=True, blank=True, default="")
    request_assert_path = models.CharField("request 断言返回值字符串--路径法", max_length=200, null=True, blank=True, default="")
    request_extract_re = models.CharField("request 正则 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    request_extract_path = models.CharField("request 路径法 提取作为临时变量", max_length=200, null=True, blank=True, default="")
    request_proxy = models.BooleanField("是否代理", default=False)
    request_group = models.IntegerField("分组--登录态持久化 0 为组长", default=0)  # cookie 持久化

    def __str__(self):
        return "自定义工具" + self.tool_id + "---" + str(self.name)

# 权限控制
class DB_power(models.Model):
    icon = models.CharField("权限功能关键字", max_length=100, default="", null=True, blank=True)
    des = models.CharField("权限描述", max_length=100, default="", null=True, blank=True)
    userIds = models.CharField("包含用户", max_length=100, default="", null=True, blank=True)

    def __str__(self):
        return self.icon


# 统计数据
class DB_useCount(models.Model):
    icon = models.CharField("功能关键字", max_length=20, null=True, blank=True)
    counts = models.IntegerField(default=0)

    def __str__(self):
        return self.icon


# models.py 文件

class Person(models.Model):
    # 姓名 str类型
    name = models.CharField(max_length=20,verbose_name='姓名')
    # 年龄 int型
    age=models.IntegerField(verbose_name='年龄')
    # 成绩 float类型
    score = models.FloatField(verbose_name='成绩')

